Component({
  properties:{
    isShow:{
      type: Boolean,
      value: false
    },
    title:{
      type: String,
      value: ''
    },
    pause:{
      type: Number,
      value: 2000
    },
    duration:{
      type: Number,
      value: 250
    },
    shade:{
      type: Boolean,
      value:true
    },
    shadeClose:{
      type: Boolean,
      value: false
    },
    maxWidth:{
      type: Number,
      optionalTypes: [String],
      value: "80%"
    },
    maxHeight:{
      type: Number,
      optionalTypes: [String],
      value: "80%"
    },
    width:{
      type: Number,
      optionalTypes: [String],
      value:"80%"
    },
    zIndex:{
      type: Number,
      optionalTypes: [String],
      value:100
    },
    height: {
      type: Number,
      optionalTypes: [String],
      value: ""
    },
    button: {
      type: Array,
      value:[
        {title:'取消',className:''},
        {title: '确认', className:''}
      ]
    },

  },
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  data:{
    wUnit:"rpx",
    hUnit:"rpx",
    W:0,
    H:0,
    scrollH:0
  },
  lifetimes: {
    attached: function () {
      var that=this;
      try {
        const sysInfo = wx.getSystemInfoSync();
        let maxW,w,maxH,h;
        //如果是百分比，计算宽度和高度
        if (this._isPercent(this.data.width)) {
          maxW = this._getNumber(this.data.maxWidth);
          w=this._getNumber(this.data.width);
          w = (w > maxW) ? (sysInfo.windowWidth * maxW / 100) : (sysInfo.windowWidth * w / 100);
          console.log(w)
          this.setData({
            W:w,
            wUnit:"px"
          })
        }
        if (this._isPercent(this.data.height)){
          maxH = this._getNumber(this.data.maxHeight);
          h = this._getNumber(this.data.height);
          h = (h > maxh) ? (sysInfo.windowHeight * maxH / 100) : (sysInfo.windowHeight * h / 100);
          console.log(h);
          this.setData({
            H: h,
            hUnit: "px"
          })
        }
        if (this.data.button.length) {
          console.log("xxx")
          const query = this.createSelectorQuery();
          query.select('.dialog-btn').boundingClientRect();
          query.exec(function (res) {
            that.setData({
              scrollH:that.data.H-res[0].height
            })

            console.log(that.data.scrollH)
          })
        }
        
      } catch (e) {
        // Do something when catch error
      }
      // wx.getSystemInfo({
      //   success(res) {
      //     console.log(res.model)
      //     console.log(res.pixelRatio)
      //     console.log(res.windowWidth)
      //     console.log(res.windowHeight)
      //     console.log(res.language)
      //     console.log(res.version)
      //     console.log(res.platform)
      //   }
      // })

      
     
    },
    moved: function () { },
    detached: function () { },
  },
  ready: function () { 
    
  },
  methods:{
    _isPercent: function (str) {
      return (typeof str == "string") ? ((str.indexOf("%") == -1) ? false : true) : false;
    },

    _getNumber: function (str) {
      return str.match(/\d+(\.\d{0,2})?/)[0]
    }
  }
})